package com.fw.jfinal;



import com.fw.controller.CommonController;
import com.fw.controller.ECommerceController;
import com.fw.controller.OrderController;
import com.fw.controller.PermissionController;
import com.fw.controller.RoleController;
import com.fw.controller.UserController;
import com.fw.filter.LoginFilter;
import com.fw.filter.UrlFilter;
import com.fw.model.Ecommerce;
import com.fw.model.Order;
import com.fw.model.Permission;
import com.fw.model.Role;
import com.fw.model.User;
import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.render.ViewType;

public class JfinalConfig extends JFinalConfig{

	@Override
	public void configConstant(Constants me) {
		me.setDevMode(false);
		me.setViewType(ViewType.JSP);
	}

	@Override
	public void configRoute(Routes me) {
		me.add("/user",UserController.class);
		me.add("/role",RoleController.class);
		me.add("/common",CommonController.class);
		me.add("/permission",PermissionController.class);
		me.add("/ecommerce",ECommerceController.class);
		me.add("/order",OrderController.class);
//		me.add("/user",UserController.class);
	}

	@Override
	public void configPlugin(Plugins me) {
		loadPropertyFile("config.properties");
		C3p0Plugin c3p0Plugin = new C3p0Plugin(getProperty("jdbcUrl"),getProperty("user"),getProperty("password"));
		me.add(c3p0Plugin);
		ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin);
		me.add(arp);
		arp.addMapping("user","u_id", User.class);
		arp.addMapping("role","r_id", Role.class);
		arp.addMapping("permission","p_id", Permission.class);
		arp.addMapping("e_commerce","id", Ecommerce.class);
		arp.addMapping("order","id", Order.class);
//		arp.addMapping("book","book_id",Book.class);
	}

	@Override
	public void configInterceptor(Interceptors me) {
		me.addGlobalActionInterceptor(new LoginFilter());
		me.addGlobalActionInterceptor(new UrlFilter());
	}

	@Override
	public void configHandler(Handlers me) {
	}

}
